<!-- 内容部分 -->
<template>
  <div class="category-content">
    <div class="left">
      <ul>
        <li
          v-for="(cateLeftData, index) in cateLeftDatas"
          :key="cateLeftData.id"
          :class="activeIndex == index ? 'active' : ''"
          @click="activeToggle(index)"
        >
          {{ cateLeftData.cat_name }}
        </li>
      </ul>
    </div>
    <div class="right">
      <div class="ad">
        <img :src="ad_img" alt="" />
      </div>
      <div class="list-wrap">
        <ul class="list">
          <li
            v-for="cateRightData in cateRightDatas"
            :key="cateRightData.cate_id"
          >
            <h4>{{ cateRightData.cate_name }}</h4>
            <ul class="innerlist">
              <li
                v-for="item in cateRightData.child"
                :key="item.id"
                @click="toGoodsList"
              >
                <img :src="item.touch_icon" alt="" />
                <p>{{ item.cat_name }}</p>
              </li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      cateLeftDatas: [
        { id: 1, cat_name: "家用电器" },
        { id: 2, cat_name: "男装女装" },
        { id: 3, cat_name: "鞋靴箱包" },
        { id: 4, cat_name: "手机数码" },
        { id: 5, cat_name: "电脑办公" },
        { id: 6, cat_name: "家居家访" },
        { id: 7, cat_name: "个人化妆" },
        { id: 8, cat_name: "休闲运动" },
      ],
      cateRightDatas: [
        {
          cate_id: 1,
          cate_name: "--厨房电器--",
          child: [
            {
              id: 11,
              cat_name: "电饭煲",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489105257655.jpg",
            },
            {
              id: 22,
              cat_name: "电饭煲",
              touch_icon:
                "https://img14.360buyimg.com/n1/s300x300_jfs/t1/134016/4/1040/200492/5ed5297cE4dd22b3d/dec0baa9b25581f2.jpg",
            },
            {
              id: 33,
              cat_name: "电饭煲",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1490175270619.jpg",
            },
            {
              id: 44,
              cat_name: "电饭煲",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1490175339477.jpg",
            },
            {
              id: 55,
              cat_name: "电饭煲",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1490175311141.jpg",
            },
            {
              id: 66,
              cat_name: "电饭煲",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201809/thumb_img/0_thumb_G_1536546954848.jpg",
            },
            {
              id: 88,
              cat_name: "电饭煲",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1490175385248.jpg",
            },
            {
              id: 99,
              cat_name: "电饭煲",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201809/thumb_img/0_thumb_G_1536601033351.jpg",
            },
            {
              id: 100,
              cat_name: "电饭煲",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489105134405.jpg",
            },
          ],
        },
        {
          cate_id: 2,
          cate_name: "--大家电--",
          child: [
            {
              id: 111,
              cat_name: "平板电视",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489105386951.jpg",
            },
            {
              id: 222,
              cat_name: "空调",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489105497655.jpg",
            },
            {
              id: 333,
              cat_name: "冰箱",
              touch_icon:
                "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1490175463945.jpg",
            },
          ],
        },
      ],
      ad_img:
        "https://x.dscmall.cn/storage/data/touch_catads/15630384831872.jpg",
      activeIndex: 0,
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    activeToggle(index){
      this.activeIndex = index;
    },
    toGoodsList() {
      this.$router.push("/goodslist")
    }
  },
  beforeCreate() {}, //生命周期 - 创建之前
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  beforeMount() {}, //生命周期 - 挂载之前
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less">
.category-content {
  width: 100%;
  height: calc(100% - 10rem);
  position: absolute;
  top: 5rem;
  left: 0;
  display: flex;
  background-color: #fff;
  .left {
    width: 8.5rem;
    height: 100%;
    background-color: #f4f4f4;
    ul {
      li {
        height: 3.8rem;
        line-height: 3.8rem;
        text-align: center;
        font-size: 1.3rem;
      }
      .active {
        background-color: #fff;
        color: rgb(226, 44, 44);
        display: flex;
        &::before {
          content: "";
          width: 0.2rem;
          height: 50%;
          margin: 1rem 1rem 0 0;
          background-color: rgb(226, 44, 44);
        }
      }
    }
  }
  .right {
    width: calc(100% - 8.5rem - 2rem);
    margin: 1rem;
    height: 100%;
    overflow: auto;
    .ad {
      width: 27rem;
      height: 9rem;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .list-wrap {
      .list {
        li {
          h4 {
            text-align: center;
            height: 2.5rem;
            line-height: 2.5rem;
            font-size: 1.3rem;
            font-weight: 400;
            color: #666;
            margin: 1rem;
          }
          .innerlist {
            display: flex;
            flex-wrap: wrap;
            li {
              width: 33%;
              text-align: center;
              margin-bottom: 2rem;
              img {
                width: 5.2rem;
                height: 5.2rem;
              }
            }
          }
        }
      }
    }
  }
  //   使滚动条隐藏
  .right::-webkit-scrollbar {
    display: none;
  }
}
</style>